package dp.test152;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/7/23 11:01
 */
public class Solution1 {

    public int maxProduct(int[] nums) {
        int n = nums.length;
        int[] dpMax = new int[n];
        int[] dpMin = new int[n];
        dpMax[0] = dpMin[0] = nums[0];
        int ans = nums[0];

        for (int i = 1; i < n; i++) {
            dpMax[i] = Math.max(Math.max(dpMax[i - 1] * nums[i], dpMin[i - 1] * nums[i]), nums[i]);
            dpMin[i] = Math.min(Math.min(dpMin[i - 1] * nums[i], dpMax[i - 1] * nums[i]), nums[i]);
            ans = Math.max(ans, dpMax[i]);
        }
        return ans;
    }
}
